Optimize MessageDifferencer::TreatAsSet time complexity to O(N * K)#28785
Draft
copybara-service[bot] wants to merge 1 commit into
Draft
Optimize MessageDifferencer::TreatAsSet time complexity to O(N * K)#28785copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
Optimizes MessageDifferencer::TreatAsSet() repeated field matching by using hash map lookup (GetRepeatedElementHash) for unmatched elements. Previously, set matching performed O(N^2 * K) element-pair comparisons. With hash map lookup, set matching executes in average O(N * K) time complexity. Updated documentation in message_differencer.h and added TreatAsSet_LargeUnorderedSet test case to message_differencer_unittest.cc. Benchmark Scaling (Old O(N^2) vs. New O(N)): Elements (N) | Old Runtime (ms) | New Runtime (ms) | Speedup ------------ | ---------------- | ---------------- | ------- N = 10 | 0.006 ms | 0.005 ms | 1.2x N = 50 | 0.102 ms | 0.033 ms | 3.1x N = 100 | 0.357 ms | 0.041 ms | 8.8x N = 500 | 8.679 ms | 0.195 ms | 44.5x N = 1,000 | 33.50 ms | 0.387 ms | 86.6x N = 5,000 | 842.48 ms | 1.930 ms | 436.5x N = 10,000 | 3325.82 ms | 3.982 ms | 835.2x speedup PiperOrigin-RevId: 952878430
copybara-service
Bot
force-pushed
the
test_952878430
branch
from
July 23, 2026 22:01
72790ba to
0e8f078
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Optimize MessageDifferencer::TreatAsSet time complexity to O(N * K)
Optimizes MessageDifferencer::TreatAsSet() repeated field matching by using
hash map lookup (GetRepeatedElementHash) for unmatched elements.
Previously, set matching performed O(N^2 * K) element-pair comparisons. With
hash map lookup, set matching executes in average O(N * K) time complexity.
Updated documentation in message_differencer.h and added
TreatAsSet_LargeUnorderedSet test case to message_differencer_unittest.cc.
Benchmark Scaling (Old O(N^2) vs. New O(N)):